﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Linq.Expressions;
using System.Windows;

namespace GSdk.Shared.Windows.Properties
{
    public struct Event<T>
    {
        Event(RoutedEvent ev)
        {
            m_RoutedEvent = ev;
        }

        readonly RoutedEvent m_RoutedEvent;

        public static implicit operator Event<T>(EventBase ev)
        {
            return new Event<T>(ev.RoutedEvent);
        }

        public static implicit operator RoutedEvent(Event<T> ev)
        {
            return ev.m_RoutedEvent;
        }
    }

    public abstract class EventBase
    {
        public readonly RoutedEvent RoutedEvent;

        protected EventBase(RoutedEvent ev)
        {
            RoutedEvent = ev;
        }
    }

    public sealed class Event<TContainer, TValue> : EventBase
    {
        public Event(Expression<Func<TContainer, TValue>> accessor)
            : base(EventManager.RegisterRoutedEvent(accessor.MemberToString(), RoutingStrategy.Direct, typeof(TValue), typeof(TContainer)))
        {
        }
        public Event(Expression<Func<TContainer, TValue>> accessor, RoutingStrategy strategy)
            : base(EventManager.RegisterRoutedEvent(accessor.MemberToString(), strategy, typeof(TValue), typeof(TContainer)))
        {
        }
    }
}
